package com.example.mntz.controller;

import com.example.mntz.model.*;
import com.example.mntz.service.MyInvestmentService;
import com.example.mntz.service.TzApiService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("/TouZi")
public class TouZiController {
    @Autowired
    TzApiService service;
    @Autowired
    MyInvestmentService investmentService;
    @GetMapping("/SelectGPJJ")
    public ResponseEntity<TzXk> SelectGPJJ(int lb, String code, HttpSession session){
        TzXk tzXk =service.contextLoads(lb,code);
        Tzjl tzjl = new Tzjl();
        tzjl.setuId(((User)session.getAttribute("session_user")).getuId());
        tzjl.setLb(lb);
        tzjl.setTzCode(code);
        service.Sctz(tzjl);
        return ResponseEntity.status(200).body(tzXk);

    }
    /*查看账户*/
    @GetMapping("/SelectZh")
    public ResponseEntity<List> SelectZh(int uId){
        List<Zq> zqs = service.selectZqs(uId);
        return ResponseEntity.status(200).body(zqs);
    }
    /*查看投资记录*/
    @GetMapping("/SelectTzjl")
    public ResponseEntity<Double> SelectTzjl(Tzjl tzjl){
        Double d = service.SelectTzjl(tzjl);
        return ResponseEntity.status(200).body(d);
    }
    /*买入*/
    @PostMapping("/MrTZ")
    @ResponseBody
    public void MrTZ(Tzjl tzjl){
        service.mrTz(tzjl);
    }
    /*卖出*/
    @PostMapping("/McTZ")
    @ResponseBody
    public void McTZ(Tzjl tzjl){
        service.mcTz(tzjl);
    }

    /*收藏投资*/
    @PostMapping("/Sctz")
    @ResponseBody
    public void Sctz(Tzjl tzjl){
        service.Sctz(tzjl);
    }


    @RequestMapping("/TzmxHtml")
    public ModelAndView TzmxHtml(String zqId,Integer uId){
        ModelAndView m  = new ModelAndView("Investment-tzmxAndtzjlList");
        m.addObject("zqId",zqId);
        m.addObject("uId",uId);
        return m;
    }

    @RequestMapping("/selectTzmx")
    @ResponseBody
    public LayuiTable selectTzmx(Integer limit, Integer page, Integer zqId,HttpSession session) {
        Integer uId = ((User)session.getAttribute("session_user")).getuId();
        return service.selectTzmx(limit,page,zqId,uId);
    }
    @RequestMapping("/selectTzqk")
    @ResponseBody
    public LayuiTable selectTzqk(Integer limit, Integer page, Integer zqId,Integer uId) {
        return service.selectTzqk(limit,page,zqId,uId);
    }
}
